
<link rel="stylesheet" href="__CDN__/assets/css/amazeui.min.css" type="text/css">
<link rel="stylesheet" href="__CDN__/assets/css/tailwind.css" type="text/css">
<script src="__CDN__/assets/js/vue.min.js"></script>
<style>
   .tpl-table-black-operation-default{ 
    color: #7f838a;
    background: #fff;
    border: solid 1px #c7c7c7;
    border-radius: 2px;
    line-height: 13px;
    box-shadow: 0 0 0 rgb(0 0 0 / 10%);
    margin-left:10px;
    padding: 2px 5px;
}


</style>
<?php $show=[]; ?>
<div id="questionnaire" v-cloak>

    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
        <div class="widget am-cf">
            <div class="widget-head am-cf">
                <!-- <div class="widget-title am-cf">问卷列表</div> -->
            </div>
            <div class="am-btn-toolbar">

                <div class="am-btn-group am-btn-group-xs">
                    <a class="am-btn am-btn-default am-btn-success am-radius"
                       href="<?= url('question_cate/add') ?>">
                        <span class="am-icon-plus"></span> 新增分类
                    </a>

                </div>
                <div class="am-btn-group am-btn-group-xs">
                    <a class="am-btn am-btn-default am-btn-success am-radius"
                       href="<?= url('question_format/index') ?>">
                        <span class="am-icon-search"></span> 查看所有问卷模板列表
                    </a>
                </div>

                <div class="am-btn-group am-btn-group-xs">
                    <a class="am-btn am-btn-default am-btn-success am-radius"
                       href="#" onclick="active()">
                         激活
                    </a>
                </div>
                <div class="am-btn-group am-btn-group-xs">
                    <a class="am-btn am-btn-default am-btn-success am-radius"
                       href="#" onclick="disabled()">
                         关闭
                    </a>
                </div>
                <div class="am-btn-group am-btn-group-xs">
                    <a class="am-btn am-btn-default am-btn-warning am-radius"
                       href="#" onclick="deletes()">
                         删除
                    </a>
                </div>

            </div>
            <div class="widget-body ">
                <!-- 工具栏 -->
                <!-- 分页 -->
                <div class="am-scrollable-horizontal am-u-sm-12">
                    <table width="100%" class="am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap">
                        <thead>
                        <tr>
                            <th>分类名字</th>
                            <th>问卷模板数</th>
                            <th>备注</th>
                            <th class="am-lg-text-center">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php if (!empty($data)): foreach ($data
                                                               as $key => $item): ?>
                            <tr>
                                <td class="am-text-middle"><?= $item['name'] ?></td>
                                <td class="am-text-middle"><?= $item['q_count'] ?></td>
                                <td class="am-text-middle"><?= $item['explanation'] ?></td>
                                <td class="am-text-middle am-lg-text-center">
                                    <div class="tpl-table-black-operation ">
                                        <?php if (checkPrivilege('')): ?>
                                            <?php $show[$key] = false; ?>
                                            <a class="j-recharge tpl-table-black-operation-default"
                                               href="javascript:void(0);"
                                               title="展开"
                                               @click="show_its_questionnaire( <?= $key ?>)"
                                            >
                                                <i class="am-icon-caret-down"></i>
                                                展开
                                            </a>
                                        <?php endif; ?>
                                        <?php if (checkPrivilege('')): ?>
                                            <a class="j-recharge tpl-table-black-operation-default "
                                               href="<?= url('question_format/add?q_class_id='.$data[$key]['q_class_id']) ?>"
                                               title="创建问卷模板"
                                            >
                                                <i class="am-icon-plus"></i>
                                                创建问卷模板
                                            </a>
                                        <?php endif; ?>
                                        <?php if (checkPrivilege('')): ?>
                                            <a class="j-grade tpl-table-black-operation-default"
                                               href="<?=url('question_cate/edit?ids='.$data[$key]['q_class_id'])?>"
                                               title="修改分类">
                                                <i class="am-icon-edit "></i>
                                                修改分类
                                            </a>
                                        <?php endif; ?>
                                        <?php if (checkPrivilege('user/delete')): ?>
                                            <a class="j-delete tpl-table-black-operation-default"
                                               href="javascript:void(0);"
                                               data-id="<?= $item['q_class_id'] ?>"
                                               title="删除分类"
                                               @click=" delete_class(<?= $item['q_class_id'] ?>)"
                                            >
                                                <i class="am-icon-trash"></i> 删除分类
                                            </a>
                                        <?php endif; ?>
                                    </div>
                                </td>
                            </tr>
                            <tr v-if="classes[ <?= $key ?>]">
                                <td colspan="5" class="   z-50 ">
                                    <table width="100%" class="bg-green-300 border-2 border-blue-400 am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap am-table-bordered ">
                                        <thead>
                                        <tr>
                                            <th></th>
                                            <th class="am-lg-text-center">标题</th>
                                            <th class="am-lg-text-center">状态</th>
                                            <!-- <th class="am-lg-text-center">分数显示模式</th> -->
                                            <!-- <th class="am-lg-text-center">自动评分</th> -->
                                       <!--      <th class="am-lg-text-center">总分</th>
                                            <th class="am-lg-text-center">及格分</th> -->
                                             <th class="am-lg-text-center">建立時間</th>
                                            <th class="am-lg-text-center">已填问卷</th>
                                            <th class="am-lg-text-center">操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php if (!empty($data[$key]['q_format']) ): foreach ($data[$key]['q_format']
                                                                                                as $k => $i): ?>
                                            <tr>
                                                <td><input type="checkbox" name="ids" value="<?= $i['id'] ?>"></td>
                                                <td class="am-text-middle am-lg-text-center"><?= $i['name'] ?></td>
                                                <td class="am-text-middle am-lg-text-center"><?= $i['available'] ? "激活" : "关闭" ?></td>
                                                <!-- <td class="am-text-middle am-lg-text-center"><?= $mode[$i['show_mode']] ?></td> -->
                                                <!-- <td class="am-text-middle am-lg-text-center"><?= $i['is_automatic']==1?"是":"否" ?></td> -->
                                               <!--  <td class="am-text-middle am-lg-text-center"><?= $i['full_mark'] ?></td>
                                                <td class="am-text-middle am-lg-text-center"><?= $i['pass_mark'] ?></td>
                                                 -->
                                                   <td class="am-text-middle am-lg-text-center"><?= Date('Y-m-d',$i['create_time']) ?></td>
                                                 <td class="am-text-middle am-lg-text-center"><?= $i['count'] ?></td>
                                                <td class="am-text-middle am-lg-text-center">
                                                    <div class="tpl-table-black-operation ">
                                                        <?php if (checkPrivilege('')): ?>
                                                            <a class="j-recharge tpl-table-black-operation-default"
                                                               href="<?= url('question_format/detail?ids='. $i['id']) ?>"
                                                               title="查看问卷模板"
                                                            >
                                                                <i class="am-icon-search"></i>
                                                                查看问卷模板
                                                            </a>
                                                        <?php endif; ?>
                                                        <?php if (checkPrivilege('')): ?>
                                                            <a class="j-grade tpl-table-black-operation-default"
                                                               href="<?= url('question_format/edit?ids='. $i['id']) ?>"
                                                               data-id="<?= $item['q_class_id'] ?>"
                                                               title="修改问卷模板">
                                                                <i class="am-icon-edit "></i>
                                                                修改问卷模板
                                                            </a>
                                                        <?php endif; ?>
                                                        <a class="j-grade tpl-table-black-operation-default"
                                                           href="<?= url('question_format/getQuestionnaireDoneList?qid='. $i['id']) ?>"
                                                           title="查看填写情况">
                                                            <i class="am-icon-edit "></i>
                                                            查看填写情况
                                                        </a>
                                                        <a class="j-grade tpl-table-black-operation-default"
                                                           href="<?= url('question_format/getQuestionnaireExcelFile?qid='. $i['id']) ?>"
                                                           title="生成Excel汇总">
                                                            <i class="am-icon-edit "></i>
                                                            生成Excel汇总
                                                        </a>
                                                        <?php if (checkPrivilege('user/delete')): ?>
                                                            <a class="j-delete tpl-table-black-operation-default"
                                                               href="javascript:void(0);"
                                                               data-id="<?= $item['q_class_id'] ?>"
                                                               title="删除问卷模板"
                                                               @click="deleteQuestionnaire(<?= $i['id'] ?>)"
                                                            >
                                                                <i class="am-icon-trash"></i> 删除问卷模板
                                                            </a>
                                                        <?php endif; ?>
                                                        <?php if (checkPrivilege('')): ?>
                                                             <a class="j-grade tpl-table-black-operation-default"
                                                               href="#"
                                                               data-id="<?= $item['q_class_id'] ?>"
                                                               @click="qcode(<?= $i['id']?>,'<?= $i['code_url']?>')"
                                                               
                                                               title="小程序二维码">
                                                                
                                                                小程序二维码
                                                            </a> 


                                                        <?php endif; ?>
                                                        <a class="j-grade tpl-table-black-operation-default"
                                                               href="__CDN__/FQfZvLoCyH.php/question_cate/statis?qid=<?= $i['id']?>"
                                                               data-id="<?= $item['q_class_id'] ?>"
                                        
                                                               
                                                               title="数据统计">
                                                                
                                                               数据统计
                                                            </a> 

                                                    </div>
                                                </td>
                                            </tr>

                                        <?php endforeach; else: ?>
                                            <tr>
                                                <td colspan="13" class="am-text-center">暂无记录</td>
                                            </tr>
                                        <?php endif; ?>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>

                        <?php endforeach; else: ?>
                            <tr>
                                <td colspan="13" class="am-text-center">暂无记录</td>
                            </tr>
                        <?php endif; ?>
                        </tbody>
                    </table>
                </div>
                <div class="am-u-lg-12 am-cf">
                    <div class="am-fr"><?= $data->render() ?> </div>
                    <div class="am-fr pagination-total am-margin-right">
                        <div class="am-vertical-align-middle">分类总数：<?= $data->total() ?></div>
                    </div>
                </div>


            </div>
        </div>
    </div>
</div>
<script>
    function active(){
        var ids = [];
         $("input:checkbox[name=\'ids\']:checked") .each(function(index,obj){
            
            ids.push($(obj).val())
            
         })
         if(ids.length < 1){
            Layer.msg('请选择要操作的数据！');
            return false;
         }
         $.post("__CDN__/FQfZvLoCyH.php/question_format/active", {ids: ids}, function (result) {
                        
            if(result.code == '1'){
                Layer.msg('操作成功');
                
                location.reload()
            }else{
                Layer.msg(result.msg);
               
            }
            return ;
        });
         

    }

    
    function deletes(){
        var ids = [];
         $("input:checkbox[name=\'ids\']:checked") .each(function(index,obj){
            
            ids.push($(obj).val())
            
         })
         if(ids.length < 1){
            Layer.msg('请选择要操作的数据！');
            return false;
         }
         $.post("__CDN__/FQfZvLoCyH.php/question_format/delete", {ids: ids}, function (result) {
                        
            if(result.code == '1'){
                
                Layer.msg('操作成功');
                location.reload()
            }else{
                Layer.msg(result.msg);
               
            }
            return ;
        });
         

    }

    function disabled(){
        var ids = [];
         $("input:checkbox[name=\'ids\']:checked") .each(function(index,obj){
            
            ids.push($(obj).val())
            
         })
         if(ids.length < 1){
            Layer.msg('请选择要操作的数据！');
            return false;
         }
         $.post("__CDN__/FQfZvLoCyH.php/question_format/disabled", {ids: ids}, function (result) {
                        
            if(result.code == '1'){
                Layer.msg('操作成功');
                location.reload()
            }else{
                Layer.msg(result.msg);
               
            }
            return ;
        });
         

    }
</script>

<script>
    var qVue = new Vue({
        el: '#questionnaire',
        data: {
            classes: <?= json_encode($show)?>
        },
        methods: {
            show_its_questionnaire: function ($key) {
                this.classes[$key] = !this.classes[$key];
                this.$forceUpdate()
            },
            delete_class: function ($q_class_id) {
                layer.confirm('删除后不可恢复，确定要删除吗？', function (index) {
                    $.post("question_cate/del", {ids: $q_class_id}, function (result) {
                        if(result.code == '1'){
                            
                            Layer.msg('操作成功');
                            setTimeout(function(){
                                parent.location.reload(true)
                            },500)
                           
                            // this.jump();
                        }else{
                            Layer.msg(result.msg);
                           
                        }
                        return ;
                    });
                    layer.close(index);
                });
            },
            deleteQuestionnaire: function ($qid) {
                layer.confirm('删除模板后会同时删除模板下已填写的问卷数据，确定要删除吗？', function (index) {
                    $.post("__CDN__/FQfZvLoCyH.php/question_format/del", {ids: $qid}, function (result) {
                        if(result.code == '1'){
                            
                            Layer.msg('操作成功');
                            setTimeout(function(){
                                parent.location.reload(true)
                            },500)
                           
                            // this.jump();
                        }else{
                            Layer.msg(result.msg);
                           
                        }
                        return ;
                    });
                    layer.close(index);
                });
            },
            qcode: function (qid,url) {
                console.log(qid,url)
                var img_url = '';
                if(url.length  < 4 ){
                    $.post("__CDN__/FQfZvLoCyH.php/question_format/getcode", {ids: qid}, function (result) {
                        
                        if(result.code == '1'){
                            
                            img_url = result.data.url
                        }else{
                            Layer.msg(result.msg);
                           
                        }
                        return ;
                    });
                }else{
                    img_url = url;
                }
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['420px', '420px'], //宽高
                    // content: '<div style="margin-left:20px;"><img src="https://ftuline.astarsw.cn/uploads/code/15_appcode.png" width="350px"></div>' 
                    content: '<div style="margin-left:20px;"><img src="'+img_url+'" width="350px"></div>'
                  });
            },


        }
    });


</script>
